<?php
namespace app\admin\model;

use think\Model;
use think\Request;

class Order extends Model
{
    public static  function getlist(Request $request)
    {
        $genData = $request->get();
        $genData = getOutpageData($genData);

        $times = '';
        if (isset($genData['datetime'])) {
            $times = explode(' - ', $genData['datetime']);
            unset($genData['datetime']);
        }

        $model=  (new self())->where($genData);
        if ($times) {
            $model->whereBetween('cdate', $times);
        }

        $res = $model->with([
            'company','user'
        ])->order('order_id','desc')
        ->paginate(10, false,[  'var_page' => 'page']);
        return $res;
    }

    # 公司
    public function company()
    {
        return $this->belongsTo(Company::class,'company_id','id');
    }

    public function user()
    {
        return $this->belongsTo(User::class,'user_id','id');
    }

}